package com.lkm.market2_0.help;

import com.lkm.frame.P;
import com.lkm.javatool.Base64Common;
import com.lkm.javatool.CollectionHelp;
import com.lkm.javatool.NumberHelp;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;




public class DataEncryptionHelp {


    public static void main(String[] args) {



        String s=  Base64Common.encode(Decrypt(new byte[]{(byte) 0xB4, 0x47 , 0x3C , 0x3D , 0x3C , 0x3E , 0x3F , 0x38 , 0x3F , 0x3A , 0x3E , 0x34 , 0x3E , 0x39 , 0x3A , 0x38 , 0x3B , 0x38 , 0x3A , 0x32 , 0x3B , 0x31 , 0x3B, 0x35},0x06,24));
       System.out.println(s);

    }
    

    public static byte[] Decrypt(byte[] data,int num,int length)  {



        byte[] nums=NumberHelp.intToBytesDesc(num);
        byte pass=(byte) (nums[3]+nums[2]);

        byte[] content=new byte[length/2];

        
        for (int i = 0; i < length; i+=2) {
            

            byte d=0;
            d|=(data[i]&0x0f)<<4;
            d|=(data[i+1]&0x0f);

            d = (byte) (d^pass);
//            contentHexSb.append(NumberHelp.bytesTohexAsc(new byte[]{d}));
            content[i/2]=d;
        }

        return content;
    }








    

    public static byte[] Encrypt(byte[] data, int num,int length ){

        byte[] nums=NumberHelp.intToBytesDesc(num);
        byte pass=(byte) (nums[3]+nums[2]);


        byte[] TempData= new byte[data.length];
        System.arraycopy(data, 0,TempData , 0, data.length);//CollectionHelp.copyOfBytes(data,new byte[data.length]);
        
        for (int i = 0; i < length; i++) {
            TempData[i]=(byte) (data[i]^pass);
        }

        byte[] content=new byte[length*2];
        
        for (int i = 0; i < length*2; i+=2) {

            byte curByte=TempData[i/2];

            
            content[i]= (byte) ((curByte & (byte) 0xf0));
            content[i]= (byte) (content[i]>>4);
            
            content[i]&=(byte)0x0f;
            content[i]|=(byte)0x30;

            
            content[i+1]= (byte) ((curByte & (byte) 0x0f));
            content[i+1]&=(byte)0x0f;
            
            content[i+1]|=(byte)0x30;
        }

        return content;

    }

    

    public static byte[] ToAscii(byte[] data, int length ){
        byte[] TempData=data;
        byte[] content=new byte[length*2];
        
        for (int i = 0; i < length*2; i+=2) {

            byte curByte=TempData[i/2];

            
            content[i]= (byte) ((curByte & (byte) 0xf0));
            content[i]= (byte) (content[i]>>4);
            
            content[i]&=(byte)0x0f;
            content[i]|=(byte)0x30;

            
            content[i+1]= (byte) ((curByte & (byte) 0x0f));
            content[i+1]&=(byte)0x0f;
            
            content[i+1]|=(byte)0x30;
        }
        return content;
    }


}
